home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / dir / dir.wrap < prev    next >
Text File  |  1999-04-29  |  6KB  |  229 lines

  1. G4C
  2.  
  3. ; This is a GUI script for the "Wrap" CLI command
  4. ; GUI script written by Graham Maddox & D.Keletsekis
  5. ; Wrap command by D.Keletsekis
  6.  
  7. ; ----------------- The window
  8.  
  9. WinBig -1 -1 240 150 'TextWrap v2.0'
  10. WinType 11110001  ; it's resizable & font sensitive with all gadgets
  11. varpath dir.gc
  12.  
  13. ; ----------------- General events
  14.  
  15. xOnLoad        ; Set the default values
  16. tw_ext = 1    ; Add extensions
  17. tw_newdir = 0        ; do not save to new dir
  18. setgad dir.wrap 2 off    ; and turn off the dir-select gadgets
  19. setgad dir.wrap 3 off
  20. tw_dest = RAM:    ; default dir to save in
  21. tw_para = 1       ; leave paragraphs alone
  22. tw_skeol = 2    ; how many end of line characters to skip
  23. tw_strhr = 0    ; don't strip carriage returns (CRs)
  24. tw_addcr = 0    ; don't add CRs
  25. tw_tabflag = 0  ; delete all tabs
  26. tw_tab = 4    ; default tab -> spaces length
  27. setgad dir.wrap 6 off
  28. tw_colflag = 1  ; Yes, change line length.
  29. tw_col = 75     ; to 75 characters per line
  30. guiopen dir.wrap
  31. run 'resident guis:c/wrap pure add'
  32.  
  33.  
  34. xOnClose
  35. delvar tw_#?
  36. guiquit dir.wrap
  37. run 'resident wrap remove'
  38.  
  39.  
  40. ; Some fancy boxes to separate the functions into sections.
  41.  
  42. box 0 0 240 51 out button
  43. box 0 52 240 36 out button
  44. box 0 89 240 35 out button
  45. box 0 125 240 25 out button
  46.  
  47.  
  48. ; ---------------- Do we want to add extensions to the files ?
  49.  
  50. xcheckbox 200 5 26 11 'Add ".wrap" extension' tw_ext 1 0 ON
  51.  
  52.  
  53. ; ---------------- Do we want to save them in an other dir ?
  54.  
  55. xcheckbox 200 17 26 11 'Save to new directory' tw_newdir 1 0 OFF
  56. if $tw_newdir = 1
  57.    setgad dir.wrap 2 on
  58.    setgad dir.wrap 3 on
  59. else
  60.    setgad dir.wrap 2 off
  61.    setgad dir.wrap 3 off
  62. endif
  63.  
  64. ; Text in for new directory
  65.  
  66. xTextIn  10 31 180 15 "" tw_dest "RAM:" 512        ; destination dir
  67. gadid 3
  68.  
  69. ; add a browse button to save typing
  70.  
  71. xbutton 190 31 40 15 "Dir"
  72. gadid 2
  73. reqfile -1 -1 300 -40 "Destination Dir..." dir tw_dest SYS:
  74. update dir.wrap 3 $tw_dest
  75.  
  76. ; ---------------- paragraph options. default is off
  77.  
  78. xcheckbox 10 57 26 11 "Paragraph" tw_para 1 0 on
  79. gadtitle right
  80. if $tw_para = 1
  81.     setgad dir.wrap 4 on
  82. else
  83.     setgad dir.wrap 4 off
  84. endif
  85.  
  86. xhslider 157 57 50 11 "EOLs" tw_skeol 0 30 2 %1ld
  87. gadtitle left
  88. gadid 4
  89.  
  90. ; ------------------- checkboxes for adding/stripping hard returns. 
  91. ; Default (unchecked) is to leave them alone.
  92. ; Check both of them if you want to re-warp PC files
  93.  
  94. xcheckbox 10 72 26 11 "StripCR" tw_strhr 1 0 off
  95. gadtitle right
  96.  
  97. xcheckbox 120 72 26 11 "AddCR" tw_addcr 1 0 off
  98. gadtitle right
  99.  
  100.  
  101. ; =====================================================================
  102. ; Now the sliders for tab settings and width. Default is tab=4 width=75
  103. ; If these are set to off, Tabs & line length will be left alone.
  104. ; NOTE : Max line length that wrap can deal with is 1000 characters.
  105.  
  106. xcheckbox 10 93  26 11 "Tabs" tw_tabflag 1 0 off
  107. gadtitle right
  108. if $tw_tabflag = 0
  109.    setgad dir.wrap 6 off
  110. else
  111.    setgad dir.wrap 6 on
  112. endif
  113.  
  114. xhslider 90 93  115 11 "" tw_tab 0 16 4 %1ld
  115. gadid 6
  116.  
  117. ; --- length slider
  118.  
  119. xcheckbox 10 108 26 11 "Length" tw_colflag 1 0 on
  120. gadtitle right
  121. if $tw_colflag = 0
  122.    setgad dir.wrap 7 off
  123. else
  124.    setgad dir.wrap 7 on
  125. endif
  126.  
  127. xhslider 90 108 115 11 "" tw_col 10 200 75 %1ld
  128. gadid 7
  129.  
  130.  
  131. ; ====================================================================
  132. ; Do yes do, that thing you do, so weeeelllll... (refrain)
  133.  
  134. xbutton 70 130 80 15 START
  135. tw_stopflag = 0            ; reset abort flag
  136. tw_lvid = $$LV.ID
  137. lvuse dir.gc $tw_lvid
  138. lvmulti first
  139. if $lv_file = ""
  140.    ezreq "I would.. if I had\nsome files.." OK ""
  141.    stop
  142. endif
  143. if $tw_ext = 0            ; check & warn if files will be overwriten
  144.    if $tw_newdir = 0
  145.       ezreq 'With the current settings\nselected files will be\nOverWriten !\n\nIf any file is not a pure\ntext file, it may be trashed!\n\nAre you sure ?\n' "Continue|CANCEL" tw_choice
  146.       if $tw_choice = 0
  147.          stop
  148.       endif
  149.    endif
  150. endif
  151. guiwindow dir.wrap wait
  152. gosub dir.wrap setup                    ; construct the command line
  153. launch 1 'wrap $lv_file $tw_options'        ; and launch the first file
  154.  
  155.  
  156. xOnReturn 1            ; upon returning, launch the next file
  157. lvuse dir.gc $tw_lvid
  158. lvmulti off
  159. if $tw_stopflag = 1        ; check if user has aborted meanwhile
  160.    guiwindow dir.wrap resume
  161.    lvdir refresh
  162.    stop
  163. endif
  164. lvmulti next
  165. if $lv_file > ""
  166.    gosub dir.wrap setup
  167.    launch 1 'wrap $lv_file $tw_options'
  168. else
  169.    guiwindow dir.wrap resume
  170.    if $tw_newdir = 1
  171.       lvdir #$tw_dest
  172.       setwintitle dir.wrap '$tw_dest                                    '
  173.    else
  174.       lvdir refresh
  175.    endif
  176. endif
  177.  
  178.  
  179. xroutine setup            ; construct the options command line
  180. tw_options = ""
  181. extract lv_file file tw_file
  182. if $tw_ext = 1
  183.    extract tw_file unquote tw_file2
  184.    appvar  tw_file2 .wrap               ; add the file extension
  185.    tw_file =  '\"$tw_file2\"'
  186. endif
  187. if $tw_newdir = 1
  188.    JoinFile $tw_dest $tw_file tw_file   ; save to new dir
  189. else
  190.    extract lv_file path tw_path
  191.    JoinFile $tw_path $tw_file tw_file   ; or to the same dir
  192. endif
  193. tw_options = '$tw_file '        ; this is our correct file name
  194. if $tw_para = 1
  195.    appvar tw_options 'PARA=$tw_skeol '  ; paragraph wraping ?
  196. endif
  197. if $tw_strhr = 1
  198.     appvar tw_options 'StripCR '    ; strip CRs ?
  199. endif
  200. if $tw_addcr = 1
  201.     appvar tw_options 'AddCR '        ; add CRs ?
  202. endif
  203. if $tw_tabflag = 1
  204.     appvar tw_options 'TAB=$tw_tab '    ; convert tabs ?
  205. endif
  206. if $tw_colflag = 1
  207.     appvar tw_options 'L=$tw_col'    ; wrap file ?
  208. endif
  209.  
  210.  
  211. ; ------------------------ Stop processing the rest of the files
  212.  
  213. xButton 150 130 80 15 _STOP
  214. tw_stopflag = 1
  215.  
  216.  
  217. ; ------------------------ If the worst happens..
  218.  
  219. xOnFail
  220. guiwindow dir.wrap resume
  221. ezreq "Error wraping file :\n$tw-file" OK ""
  222.  
  223.  
  224. ; ------------------------- Must tell everyone how great I am..... 8)
  225.  
  226. xbutton 20 130 26 15  _?
  227. EzReq "TextWrap 2.0\n\nBy :\nG.Maddox & D.Keletsekis\n\nFor use with the c:Wrap\ncommand, by D.Keletsekis\n" "Who cares.." opt
  228.  
  229.